package model;

import javax.microedition.lcdui.Graphics;

import screen.PaintPopup;
import font.BitmapFont;

public class Quest extends Item {
	public static final int QUEST_TYPE_FEED_PET 			= 1;
	public static final int QUEST_TYPE_TAKE_A_BATH_PET		= 2;
	public static final int QUEST_TYPE_BUY_ITEM		 		= 3;
	public static final int QUEST_TYPE_MAKE_FRIEND			= 4;
	public static final int QUEST_TYPE_HARVEST_MONEY		= 5;
	public static final int QUEST_TYPE_GO_DOCTOR			= 6;
	public static final int QUEST_TYPE_SELL_PET				= 7;//nhiem vu ban thu
	
	public int m_iCurrentNumber;
	
	//item of quest
	public int m_iItemType;
	public int m_iItemID;
	
	public void setQuestData(String strData){
		switch (m_bItemType) {
		case QUEST_TYPE_MAKE_FRIEND:
		case QUEST_TYPE_HARVEST_MONEY:
			m_iNumItem = Integer.parseInt(strData);
			break;
			
		case QUEST_TYPE_FEED_PET:
		case QUEST_TYPE_TAKE_A_BATH_PET:
		case QUEST_TYPE_SELL_PET:
			String s[] = BitmapFont.splitString(strData, ",");
			m_iItemID = Integer.parseInt(s[0]);
			m_iNumItem = Integer.parseInt(s[1]);
			break;
			
		case QUEST_TYPE_BUY_ITEM:
		case QUEST_TYPE_GO_DOCTOR:
			s = BitmapFont.splitString(strData, ",");
			m_iItemType =Integer.parseInt(s[0]);
			m_iItemID = Integer.parseInt(s[1]);
			m_iNumItem = Integer.parseInt(s[2]);
			break;
		default:
			break;
		}
	}
	
	public void paint(Graphics g) {
		// TODO Auto-generated method stub	
	}
	
	public void paintIcon(Graphics g, int x, int y) {
		// TODO Auto-generated method stub
	}
	
	public void paintInRow(Graphics g, int x, int y, int width, int height, boolean select) {
		// TODO Auto-generated method stub
		int tmpY = y + height/2;
		
		int choose = (select)?2:1;
		PaintPopup.drawCheckbox(g, x, y+5, 11, 11, choose, false);
		if(m_iCurrentNumber >= m_iNumItem){
			PaintPopup.drawCheckbox(g, x, y+5, 11, 11, choose, true);
			m_iCurrentNumber = m_iNumItem;
		}
		
		String str = m_iCurrentNumber + "/" + m_iNumItem;
		BitmapFont.drawBoldFont(g, str, x + width, tmpY - 10, 0xff3e45, Graphics.RIGHT);
		
		
		int remainLength = width - BitmapFont.m_facedeFont.stringWidth(str) - 30;
		String arr[] = BitmapFont.m_bmFont.splitFontBStrInLine(m_strName, remainLength);
		
		tmpY -= 15;
		if(arr.length >= 2){
            int a = arr.length;
			for(int i = 0; i < a; i++){
				BitmapFont.drawNormalFont(g, arr[i], x + 15, tmpY, 0x3a001e, Graphics.LEFT | Graphics.TOP);
				tmpY += 15;
			}
		}
		else{
			BitmapFont.drawNormalFont(g, m_strName, x + 15, tmpY, 0x3a001e, Graphics.LEFT | Graphics.TOP);
		}
	}
	
	public void paintInfo(Graphics g, int x, int y) {
		// TODO Auto-generated method stub
	}
	
	public void update() {
		// TODO Auto-generated method stub
	}
}
